import express from "express";
import authRouter from "../routes/auth";
import userRouter from "../routes/user";
import roomRouter from "../routes/room";
import { errorHandler } from "../middlewares/error-handler";
import { tokenVerifier } from "../middlewares/token-verifier";
import { resolve } from "path";
import multer from "multer";

const app = express();
export const expressInit = () => {
	const staticPath = resolve(import.meta.dirname, "../../public");
	const upload = multer({ dest: staticPath + "/temp" });
	app.use(upload.any());
	app.use("/public", express.static(staticPath));
	app.use(express.json());
	app.use("/api/auth", authRouter);
	app.use(tokenVerifier);
	app.use("/api/user", userRouter);
	app.use("/api/room", roomRouter);
	app.use(errorHandler);
	app.listen(3000, () => console.log("Server is running"));
};
